package com.hubu.jwxt.controller;

import com.hubu.jwxt.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public String login(String num, String pwd, String role, HttpServletRequest request){
        Map rs = loginService.check(num,pwd,role);
        if (rs.get("user")!=null){
            //登录成功
            //用户信息，用户角色存放的session
            request.getSession().setAttribute("user",rs.get("user"));
            request.getSession().setAttribute("role",role);
            //跳转到页面
            return "/index.html";
        }else {
            //登录失败
            request.setAttribute("msg",rs.get("msg"));
            return "/login.html";
        }
    }

}
